package com.mzy;

import java.util.Arrays;

public class MyRandToRand {

    public static void main(String[] args) {
        int[] arr = new int[70];
        int count = 0;
        for (int i = 0; i < 1000000; i++) {
            int i1 = f4();
            if( i1 == 68){
                count++;
            }
        }
        // Arrays.stream(arr).forEach(System.out::println);
        System.out.println(count);

    }

    /**
     * 17 ~ 58 => [17,58]
     *
     * @return
     */
    public static int f1() {
        // 0.7*58
        return (int) (Math.random() * (58 - 17)) + 18;
    }

    /**
     * 0 or 1
     *
     * @return
     */
    public static int f2() {
        int ans = 0;
        do {
            ans = f1();
        } while (ans == 38);

        return ans > 38 ? 0 : 1;
    }

    /**
     * 20~68
     *
     * @return
     */
    public static int f3() {
        int ans = (f2() << 6) + (f2() << 5) + (f2() << 4) + (f2() << 3) + (f2() << 2) + (f2() << 1) + (f2() << 0);
        return ans;
    }

    public static int f4() {
        int ans = 0;
        do {
            ans = f3();
        } while (ans > 68 || ans < 20);
        return ans;
    }
}
